# Maintainer: Alexey Minnekhanov <alexeymin@postmarketos.org>
# Co-Maintainer: Luca Weiss <luca@lucaweiss.eu>
_flavor=postmarketos-qcom-msm8974
_config="config-$_flavor.$CARCH"

pkgname=linux-$_flavor
pkgver=6.11.4
pkgrel=1
_tag="v${pkgver/_/-}-msm8974"
pkgdesc="Kernel close to mainline with extra patches for Qualcomm MSM8974 devices"
arch="armv7"
_carch="arm"
url="https://kernel.org/"
license="GPL-2.0-only"
options="!strip !check !tracedeps
	pmb:cross-native
	pmb:kconfigcheck-community
	"
makedepends="
	bash
	bison
	findutils
	flex
	gmp-dev
	mpc1-dev
	mpfr-dev
	openssl-dev
	perl
	postmarketos-installkernel
	python3
	"
source="
	linux-$_tag.tar.gz::https://github.com/msm8974-mainline/linux/archive/refs/tags/$_tag.tar.gz
	config-$_flavor.armv7
	"
builddir="$srcdir/linux-${_tag#v}"

prepare() {
	default_prepare
	cp "$srcdir/config-$_flavor.$CARCH" .config
}

build() {
	unset LDFLAGS
	make ARCH="$_carch" CC="${CC:-gcc}" \
		KBUILD_BUILD_VERSION="$((pkgrel + 1 ))-$_flavor"
}

package() {
	mkdir -p "$pkgdir"/boot
	make zinstall modules_install dtbs_install \
		ARCH="$_carch" \
		INSTALL_PATH="$pkgdir"/boot \
		INSTALL_MOD_PATH="$pkgdir" \
		INSTALL_MOD_STRIP=1 \
		INSTALL_DTBS_PATH="$pkgdir"/boot/dtbs
	rm -f "$pkgdir"/lib/modules/*/build "$pkgdir"/lib/modules/*/source

	install -D "$builddir/include/config/kernel.release" \
		"$pkgdir/usr/share/kernel/$_flavor/kernel.release"
}

sha512sums="
309c67155f975445fb24006a14c0e1a12d922e607dd64949b9b7dcc09737c80f098a0857e11d13ec3a78377216342bd1b6725ed0c7a56b5ecb51ca07936c8bc1  linux-v6.11.4-msm8974.tar.gz
0d3094f6e70e58d6f586f8517de695f4bf6258a0c3b9057c8b3fdc78efb643db1f9533f9883eba2682e7d960fd566d96cbbc06777528d58ca276691c0dd92a72  config-postmarketos-qcom-msm8974.armv7
"
